<?php
function webform_submission_render_DE($node, $submission, &$components, $format) {
  $split_family_show = FALSE;
  $split_family_cid  = 0;
  $salary_change_date_show = FALSE;
  $salary_change_date_cid = 0;
  $rlm_confirm_info_show = TRUE;
  $rlm_confirm_info_cid = 0;
  $not_rlm_confirm_info_show = TRUE;
  $not_rlm_confirm_info_cid = 0;
  
  $line_manager_name_show = TRUE;
  $line_manager_name_cid = 0;
  $line_manager_email_show = TRUE;
  $line_manager_email_cid = 0;
  $approver_notice_show = TRUE;
  $approver_notice_cid = 0;
  $approver_name_show = TRUE;
  $approver_name_cid = 0;
  $approver_email_show = TRUE;
  $approver_email_cid = 0;
  $approver_file_show = TRUE;
  $approver_file_cid = 0;
  
  //robert add 2012-09-21 [hidden the markup notice]
  $for_allowances_calculation_show = TRUE;
  $for_allowances_calculation_cid = 37;
  $notice_for_allowances_calculation_show = FALSE;
  $notice_for_allowances_calculation_cid = 38;
  $is_salary_change_show = FALSE;
  $is_salary_change_cid = 23;
  $is_salary_change_description_show = FALSE;
  $is_salary_change_description_cid = 64;
  //end robert add 2012-09-21
  
  // phase 2: change for Germany by tanky
  // Sending Work Location/Site : - Display if "Relocation Type" <> 'New Hire'
  // Sending Location/City :Display if "Relocation Type" = 'New Hire'
  // Sending Please specify : Display if "Sending Location/City" = 'Other'
  // Receiving Please specify : Display if "Receiving Location/City" = 'Other'
  $sending_work_site_show = TRUE;
  $sending_work_site_cid = 0;
  $sending_work_city_show = TRUE;
  $sending_work_city_cid = 0;
  $sending_work_city_specify_show = FALSE;
  $sending_work_city_specify_cid = 0;
  $receiving_work_city_specify_show = FALSE;
  $receiving_work_city_specify_cid = 0;
  
  // SAP ID/Personnel Number : Non-mandatory if "Relocation Type" = 'New Hire'
  $global_sap_id_mandatory = TRUE;
  $global_sap_id_cid = 0;
  // P&G Email Address : Non-mandatory if "Relocation Type" = 'New Hire'
  $email_address_mandatory = TRUE;
  $email_address_cid = 0;
  // Email Address 2: Display if "Relocation Type" = 'New Hire'
  $email_address_2_show = FALSE;
  $email_address_2_cid = 0;
  //end phase 2: change for Germany by tanky
  //phase 4 Is the Spouse/Partner a P&G Employee lower: 3 question:
  $spouse_full_name_show = FALSE;
  $spouse_full_name_cid= 0 ;
  $spouse_being_transfer_show = FALSE;
  $spouse_being_transfer_cid= 0 ;
  $spouse_id_show = FALSE;
  $spouse_id_cid= 0 ;
  
  foreach ($components as $cid=>$value) {
	if ($value['form_key']=='relocation_type') {//cid:24
            if ($submission->data[$value['cid']]['value'][0] == 'new_hire') {
//                $sending_work_site_show = TRUE;
//                $sending_work_city_show = TRUE;
                $email_address_2_show = TRUE;
                $global_sap_id_mandatory = FALSE;
                $email_address_mandatory = FALSE;
            }
            else {
                // <> 'New Hire'
//                $sending_work_site_show = TRUE;
//                $sending_work_city_show = FALSE;
            }
            
            // Split Family : Display if "Relocation Type" = 'National Transfer Guide'
            if ($submission->data[$value['cid']]['value'][0] == 'experienced_employee') {
                $split_family_show = TRUE;
            }
	}
        if ($value['form_key'] == 'sending_work_location_site') {//cid:25
            $sending_work_site_cid = $value['cid'];
        }
        if ($value['form_key'] == 'sending_work_city') {//cid:57
            $sending_work_city_cid = $value['cid'];
            if ($submission->data[$value['cid']]['value'][0] == LOCATION_CITY_OTHERS) {
                $sending_work_city_specify_show = TRUE;
            }
         }
        if ($value['form_key'] == 'please_specify_sending') {//cid:65
            $sending_work_city_specify_cid = $value['cid'];
        }
        if ($value['form_key'] == 'receiving_work_city') {//cid:61
            if ($submission->data[$value['cid']]['value'][0] == LOCATION_CITY_OTHERS) {
                $receiving_work_city_specify_show = TRUE;
            }
        }
        if ($value['form_key'] == 'please_specify_receiving') {//cid:66
            $receiving_work_city_specify_cid = $value['cid'];
        }
        if ($value['form_key'] == 'receiving_company_legal_entity2') {
            $receiving_company_legal_entity2_cid = $value['cid'];
          }
          if ($value['form_key'] == 'company_code') {
            $field_company_code_cid = $value['cid'];
          }
          if ($value['form_key'] == 'company_name') {
            $field_company_name_cid = $value['cid'];
          }
        if ($value['form_key'] == 'global_sap_id') {//cid:63
            $global_sap_id_cid = $value['cid'];
        }
        if ($value['form_key'] == 'email_address') {//cid:33
            $email_address_cid = $value['cid'];
        }
        if ($value['form_key'] == 'email_address_2') {//cid:67
            $email_address_2_cid = $value['cid'];
        }
	if ($value['form_key']=='split_family') {//cid:52
	  $split_family_cid = $value['cid'];
	}
	if($value['form_key']=='is_salary_change' && $submission->data[$value['cid']]['value'][0]!='Yes') {//cid:23
	  //$salary_change_date_show = FALSE;
	}
	if ($value['form_key']=='salary_change_date') {//cid:27
	  $salary_change_date_cid = $value['cid'];
	}
	if ($value['form_key']=='relocation_initiator_role') {//cid:22
	  if ($submission->data[$value['cid']]['value'][0]!='RLM') {	
	    $rlm_confirm_info_show = FALSE;
	  }
	  else {
	    $line_manager_name_show = FALSE;
            $line_manager_email_show = FALSE;	  
		  
	    $not_rlm_confirm_info_show = FALSE;
	  }
	}
	if ($value['form_key']=='rlm_confirm_info') {//cid:53
	  $rlm_confirm_info_cid = $value['cid'];
	}
	if ($value['form_key']=='not_rlm_confirm_info') {//cid:56
	  $not_rlm_confirm_info_cid = $value['cid'];
	}
	if ($value['form_key']=='name_of_receiving_line_manager') {//cid:11
	  $line_manager_name_cid = $value['cid'];
	}
	if ($value['form_key']=='receiving_line_manager_email') {//cid:41
	  $line_manager_email_cid = $value['cid'];
	}
	if ($value['form_key']=='is_relocation_initiator_acting_as_approver' && $submission->data[$value['cid']]['value'][0]==1) {//cid:40
	  $approver_notice_show = FALSE;
  	  $approver_name_show = FALSE;
          $approver_email_show = FALSE;
          $approver_file_show = FALSE;
	}
	if ($value['form_key']=='notice_display_approver') {//cid:46
	  $approver_notice_cid = $value['cid'];
	}
	if ($value['form_key']=='name_of_approver') {//cid:18
	  $approver_name_cid = $value['cid'];
	}
	if ($value['form_key']=='approver_email') {//cid:42
	  $approver_email_cid = $value['cid'];
	}
	if ($value['form_key']=='please_attach_approval_notification') {//cid:43
	  $approver_file_cid = $value['cid'];
	}
        if ($value['form_key']=='is_the_spouse_partner_a_pg_employee' && $submission->data[$value['cid']]['value'][0]==1) {//cid:43
            $spouse_full_name_show = TRUE;
            $spouse_being_transfer_show = TRUE;
            $spouse_id_show = TRUE;
	}
        if ($value['form_key']=='if_yes_please_provide_spouse_partners_full_name') {//cid:43
	  $spouse_full_name_cid = $value['cid'];
	}
        if ($value['form_key']=='is_spouse_partner_also_being_transferred') {//cid:43
	  $spouse_being_transfer_cid = $value['cid'];
	}
        if ($value['form_key']=='spouse_partners_sap_id_personnel_number') {//cid:43
	  $spouse_id_cid = $value['cid'];
	}
  }//endforeach
  
  if (!$split_family_show && isset($components[$split_family_cid])) {
    unset($components[$split_family_cid]);
  }
  if (!$salary_change_date_show && isset($components[$salary_change_date_cid])) {
    unset($components[$salary_change_date_cid]);
  }
  if (!$rlm_confirm_info_show && isset($components[$rlm_confirm_info_cid])) {
    unset($components[$rlm_confirm_info_cid]);
  }
  if (!$not_rlm_confirm_info_show && isset($components[$not_rlm_confirm_info_cid])) {
    unset($components[$not_rlm_confirm_info_cid]);
  }
  if (!$line_manager_name_show && isset($components[$line_manager_name_cid])) {
    unset($components[$line_manager_name_cid]);
  }
  if (!$line_manager_email_show && isset($components[$line_manager_email_cid])) {
    unset($components[$line_manager_email_cid]);
  }
  if (!$approver_notice_show && isset($components[$approver_notice_cid])) {
    unset($components[$approver_notice_cid]);
  }
  if (!$approver_name_show && isset($components[$approver_name_cid])) {
    unset($components[$approver_name_cid]);
  }
  if (!$approver_email_show && isset($components[$approver_email_cid])) {
    unset($components[$approver_email_cid]);
  }
  if (!$approver_file_show && isset($components[$approver_file_cid])) {
    unset($components[$approver_file_cid]);
  }
  
  //robert add 2012-09-21 [hidden the markup notice]
  if (!$for_allowances_calculation_show && isset($components[$for_allowances_calculation_cid])) {
    unset($components[$for_allowances_calculation_cid]);
  }
  if (!$notice_for_allowances_calculation_show && isset($components[$notice_for_allowances_calculation_cid])) {
    unset($components[$notice_for_allowances_calculation_cid]);
  }
  if (!$is_salary_change_show && isset($components[$is_salary_change_cid])) {
    unset($components[$is_salary_change_cid]);
  }
  if (!$is_salary_change_description_show && isset($components[$is_salary_change_description_cid])) {
    unset($components[$is_salary_change_description_cid]);
  }
  //end robert add 2012-09-21
  
  // phase 2: change for Germany by tanky
  if (!$sending_work_site_show && isset($components[$sending_work_site_cid])) {
    unset($components[$sending_work_site_cid]);
  }
  if (!$sending_work_city_show && isset($components[$sending_work_city_cid])) {
    unset($components[$sending_work_city_cid]);
  }
  if (!$sending_work_city_specify_show && isset($components[$sending_work_city_specify_cid])) {
    unset($components[$sending_work_city_specify_cid]);
  }
  if (!$receiving_work_city_specify_show && isset($components[$receiving_work_city_specify_cid])) {
    unset($components[$receiving_work_city_specify_cid]);
  }
  if (!$global_sap_id_mandatory) {
    unset($components[$global_sap_id_cid]['mandatory']);
  }
  if (!$email_address_mandatory) {  
    unset($components[$email_address_cid]['mandatory']);
  }
  if (!$email_address_2_show && isset($components[$email_address_2_cid])) {
    unset($components[$email_address_2_cid]);
  }
  //end phase 2: change for Germany by tanky
  //phase 4 spouse employee
  if (!$spouse_full_name_show && isset($components[$spouse_full_name_cid])) {
    unset($components[$spouse_full_name_cid]);
  }
  if (!$spouse_being_transfer_show && isset($components[$spouse_being_transfer_cid])) {
    unset($components[$spouse_being_transfer_cid]);
  }
  if (!$spouse_id_show && isset($components[$spouse_id_cid])) {
    unset($components[$spouse_id_cid]);
  }
if ($submission->data[$receiving_company_legal_entity2_cid]['value'][0] != '0000|None of above|None') {
    unset($components[$field_company_code_cid]);
    unset($components[$field_company_name_cid]);
  }
  //show the * in detail page
  foreach ($components as $cid => $value) {
    if (isset($value['mandatory']) && $value['mandatory'] == 1) {
      if ($format != "text") {
        $components[$cid]['name'] .= '<span class="form-required" title="This field is required.">*</span>';
      }
    }
  }
  //end show the * in detail page
}

function webform_submission_render_JAP($node, $submission, &$components, $format) {
  //$split_family_show = TRUE;
  //$split_family_cid  = 0;
  $salary_change_date_show = TRUE;
  $salary_change_date_cid = 0;
  $rlm_confirm_info_show = TRUE;
  $rlm_confirm_info_cid = 0;
  $not_rlm_confirm_info_show = TRUE;
  $not_rlm_confirm_info_cid = 0;

  $line_manager_name_show = TRUE;
  $line_manager_name_cid = 0;
  $line_manager_email_show = TRUE;
  $line_manager_email_cid = 0;
  $approver_notice_show = TRUE;
  $approver_notice_cid = 0;
  $approver_name_show = TRUE;
  $approver_name_cid = 0;
  $approver_email_show = TRUE;
  $approver_email_cid = 0;
  $approver_file_show = TRUE;
  $approver_file_cid = 0;

  //robert add 2012-09-21 [hidden the markup notice]
  //$for_allowances_calculation_show = TRUE;
  //$for_allowances_calculation_cid = 37;
  $notice_for_allowances_calculation_show = FALSE;
  $notice_for_allowances_calculation_cid = 38;
  //$is_salary_change_show = FALSE;
  //$is_salary_change_cid = 23;
  $is_salary_change_description_show = FALSE;
  $is_salary_change_description_cid = 64;
  //end robert add 2012-09-21
  
  // phase 2: add for Japan by tanky
  // Sending Work Location/Site : Display if "Is the employee a New Hire" = 'N'
  // Sending Location/City : Display if "Is the employee a New Hire" = 'Y'
  // Sending Please specify : Display if "Sending Location/City" = 'Other'
  // Receiving Please specify : Display if "Receiving Location/City" = 'Other'
  $sending_work_site_show = TRUE;
  $sending_work_site_cid = 0;
  $sending_work_city_show = TRUE;
  $sending_work_city_cid = 0;
  $sending_work_city_specify_show = FALSE;
  $sending_work_city_specify_cid = 0;
  $receiving_work_site_show = TRUE;
  $receiving_work_site_cid = 0;
  $receiving_work_city_specify_show = FALSE;
  $receiving_work_city_specify_cid = 0;
  
  $global_sap_id_show = FALSE;
  $global_sap_id_cid = 0;
  $email_address_show = FALSE;
  $email_address_cid = 0;
  // Email Address : Display if "Relocation Type" = 'Temporary BC Domestic Relocation' or 'Permanent BC Domestic Relocation', AND "Is the employee a New Hire" = 'Y'
  $email_address_2_show = FALSE;
  $email_address_2_cid = 0;
  $is_relocation_type_BC = FALSE;
  $is_new_hire_Yes = FALSE;
  //end phase 2: add for Japan by tanky
  //phase 4 Is the Spouse/Partner a P&G Employee lower: 3 question:
  $spouse_full_name_show = FALSE;
  $spouse_full_name_cid= 0 ;
  $spouse_being_transfer_show = FALSE;
  $spouse_being_transfer_cid= 0 ;
  $spouse_id_show = FALSE;
  $spouse_id_cid= 0 ;
  foreach ($components as $cid => $value) {
    if ($value['form_key'] == 'relocation_type' && ($submission->data[$value['cid']]['value'][0] == 'temporary_bc_domestic'
            || $submission->data[$value['cid']]['value'][0] == 'permanent_bc_domestic')) {//cid:24
      $is_relocation_type_BC = TRUE;
    }
    if ($value['form_key'] == 'is_the_employee_a_new_hire') {//cid:65
      if ($submission->data[$value['cid']]['value'][0] == 1) {//yes
//        $sending_work_site_show = FALSE;
        $is_new_hire_Yes = TRUE;
      } else {//no
//        $sending_work_city_show = FALSE;
      }
    }
    if ($value['form_key'] == 'sending_work_location_site') {//cid:25
      $sending_work_site_cid = $value['cid'];
    }
    if ($value['form_key'] == 'sending_work_city') {//cid:57
      $sending_work_city_cid = $value['cid'];
      if ($submission->data[$value['cid']]['value'][0] == LOCATION_CITY_OTHERS) {
        $sending_work_city_specify_show = TRUE;
      }
    }
    if ($value['form_key'] == 'please_specify_sending') {//cid:66
      $sending_work_city_specify_cid = $value['cid'];
    }
    if ($value['form_key'] == 'receiving_work_location_site') {
      $receiving_work_site_cid = $value['cid'];
    }
    if ($value['form_key'] == 'receiving_work_city') {//cid:61
      if ($submission->data[$value['cid']]['value'][0] == LOCATION_CITY_OTHERS) {
        $receiving_work_city_specify_show = TRUE;
      }
    }
    if ($value['form_key'] == 'please_specify_receiving') {//cid:67
      $receiving_work_city_specify_cid = $value['cid'];
    }
    if ($value['form_key'] == 'receiving_company_legal_entity2') {
      $receiving_company_legal_entity2_cid = $value['cid'];
    }
    if ($value['form_key'] == 'company_code') {
      $field_company_code_cid = $value['cid'];
    }
    if ($value['form_key'] == 'company_name') {
      $field_company_name_cid = $value['cid'];
    }
    if ($value['form_key'] == 'global_sap_id') {//cid:63
      $global_sap_id_cid = $value['cid'];
    }
    if ($value['form_key'] == 'email_address') {//cid:33
      $email_address_cid = $value['cid'];
    }
    if ($value['form_key'] == 'email_address_2') {//cid:68
      $email_address_2_cid = $value['cid'];
    }
    if ($value['form_key'] == 'split_family') {//cid:52
      //$split_family_cid = $value['cid'];
    }
    if ($value['form_key'] == 'is_salary_change' && $submission->data[$value['cid']]['value'][0] != 'Yes') {//cid:23
      $salary_change_date_show = FALSE;
    }
    if ($value['form_key'] == 'salary_change_date') {//cid:27
      $salary_change_date_cid = $value['cid'];
    }
    if ($value['form_key'] == 'relocation_initiator_role') {//cid:22
      if ($submission->data[$value['cid']]['value'][0] != 'RLM') {
        $rlm_confirm_info_show = FALSE;
      } else {
        $line_manager_name_show = FALSE;
        $line_manager_email_show = FALSE;

        $not_rlm_confirm_info_show = FALSE;
      }
    }
    if ($value['form_key'] == 'rlm_confirm_info') {//cid:53
      $rlm_confirm_info_cid = $value['cid'];
    }
    if ($value['form_key'] == 'not_rlm_confirm_info') {//cid:56
      $not_rlm_confirm_info_cid = $value['cid'];
    }
    if ($value['form_key'] == 'name_of_receiving_line_manager') {//cid:11
      $line_manager_name_cid = $value['cid'];
    }
    if ($value['form_key'] == 'receiving_line_manager_email') {//cid:41
      $line_manager_email_cid = $value['cid'];
    }
    if ($value['form_key'] == 'is_relocation_initiator_acting_as_approver' && $submission->data[$value['cid']]['value'][0] == 1) {//cid:40
      $approver_notice_show = FALSE;
      $approver_name_show = FALSE;
      $approver_email_show = FALSE;
      $approver_file_show = FALSE;
    }
    if ($value['form_key'] == 'notice_display_approver') {//cid:46
      $approver_notice_cid = $value['cid'];
    }
    if ($value['form_key'] == 'name_of_approver') {//cid:18
      $approver_name_cid = $value['cid'];
    }
    if ($value['form_key'] == 'approver_email') {//cid:42
      $approver_email_cid = $value['cid'];
    }
    if ($value['form_key'] == 'please_attach_approval_notification') {//cid:43
      $approver_file_cid = $value['cid'];
    }
    if ($value['form_key']=='is_the_spouse_partner_a_pg_employee' && $submission->data[$value['cid']]['value'][0]==1) {//cid:43
        $spouse_full_name_show = TRUE;
        $spouse_being_transfer_show = TRUE;
        $spouse_id_show = TRUE;
    }
    if ($value['form_key']=='if_yes_please_provide_spouse_partners_full_name') {//cid:43
      $spouse_full_name_cid = $value['cid'];
    }
    if ($value['form_key']=='is_spouse_partner_also_being_transferred') {//cid:43
      $spouse_being_transfer_cid = $value['cid'];
    }
    if ($value['form_key']=='spouse_partners_sap_id_personnel_number') {//cid:43
      $spouse_id_cid = $value['cid'];
    }
  }//endforeach
  
  //if (!$split_family_show && isset($components[$split_family_cid])) {
  //unset($components[$split_family_cid]);
  //}
  if (!$salary_change_date_show && isset($components[$salary_change_date_cid])) {
    unset($components[$salary_change_date_cid]);
  }
  if (!$rlm_confirm_info_show && isset($components[$rlm_confirm_info_cid])) {
    unset($components[$rlm_confirm_info_cid]);
  }
  if (!$not_rlm_confirm_info_show && isset($components[$not_rlm_confirm_info_cid])) {
    unset($components[$not_rlm_confirm_info_cid]);
  }
  if (!$line_manager_name_show && isset($components[$line_manager_name_cid])) {
    unset($components[$line_manager_name_cid]);
  }
  if (!$line_manager_email_show && isset($components[$line_manager_email_cid])) {
    unset($components[$line_manager_email_cid]);
  }
  if (!$approver_notice_show && isset($components[$approver_notice_cid])) {
    unset($components[$approver_notice_cid]);
  }
  if (!$approver_name_show && isset($components[$approver_name_cid])) {
    unset($components[$approver_name_cid]);
  }
  if (!$approver_email_show && isset($components[$approver_email_cid])) {
    unset($components[$approver_email_cid]);
  }
  if (!$approver_file_show && isset($components[$approver_file_cid])) {
    unset($components[$approver_file_cid]);
  }

  //robert add 2012-09-21 [hidden the markup notice]
  //if (!$for_allowances_calculation_show && isset($components[$for_allowances_calculation_cid])) {
  //unset($components[$for_allowances_calculation_cid]);
  //}
  if (!$notice_for_allowances_calculation_show && isset($components[$notice_for_allowances_calculation_cid])) {
    unset($components[$notice_for_allowances_calculation_cid]);
  }
  //if (!$is_salary_change_show && isset($components[$is_salary_change_cid])) {
  //unset($components[$is_salary_change_cid]);
  //}
  if (!$is_salary_change_description_show && isset($components[$is_salary_change_description_cid])) {
    unset($components[$is_salary_change_description_cid]);
  }
  //end robert add 2012-09-21
  
  // phase 2: add for Japan by tanky
  if($is_relocation_type_BC) {
     unset($components[$sending_work_site_cid]['mandatory']);
     unset($components[$receiving_work_site_cid]['mandatory']);
  }
  if (!$sending_work_site_show && isset($components[$sending_work_site_cid])) {
    unset($components[$sending_work_site_cid]);
  }
  if (!$sending_work_city_show && isset($components[$sending_work_city_cid])) {
    unset($components[$sending_work_city_cid]);
  }
  if (!$sending_work_city_specify_show && isset($components[$sending_work_city_specify_cid])) {
    unset($components[$sending_work_city_specify_cid]);
  }
  if (!$receiving_work_city_specify_show && isset($components[$receiving_work_city_specify_cid])) {
    unset($components[$receiving_work_city_specify_cid]);
  }
  if ($is_new_hire_Yes) {
    unset($components[$global_sap_id_cid]['mandatory']);
  }
  if ($is_relocation_type_BC && $is_new_hire_Yes) {
    $email_address_2_show = TRUE;
    unset($components[$email_address_cid]['mandatory']);
  }
  if (!$email_address_2_show && isset($components[$email_address_2_cid])) {
    unset($components[$email_address_2_cid]);
  }
  //end phase 2: add for Japan by tanky
    //phase 4 spouse employee
  if (!$spouse_full_name_show && isset($components[$spouse_full_name_cid])) {
    unset($components[$spouse_full_name_cid]);
  }
  if (!$spouse_being_transfer_show && isset($components[$spouse_being_transfer_cid])) {
    unset($components[$spouse_being_transfer_cid]);
  }
  if (!$spouse_id_show && isset($components[$spouse_id_cid])) {
    unset($components[$spouse_id_cid]);
  }
    if ($submission->data[$receiving_company_legal_entity2_cid]['value'][0] != '0000|None of above|None') {
    unset($components[$field_company_code_cid]);
    unset($components[$field_company_name_cid]);
  }
  //show the * in detail page
  foreach ($components as $cid => $value) {
    if (isset($value['mandatory']) && $value['mandatory'] == 1) {
      if ($format != "text") {
        $components[$cid]['name'] .= '<span class="form-required" title="This field is required.">*</span>';
      }
    }
  }
  //end show the * in detail page
}

function webform_submission_render_TUR($node, $submission, &$components, $format) {
  //$split_family_show = TRUE;
  //$split_family_cid  = 0;
  $salary_change_date_show = TRUE;
  $salary_change_date_cid = 0;
  $rlm_confirm_info_show = TRUE;
  $rlm_confirm_info_cid = 0;
  $not_rlm_confirm_info_show = TRUE;
  $not_rlm_confirm_info_cid = 0;
  
  $line_manager_name_show = TRUE;
  $line_manager_name_cid = 0;
  $line_manager_email_show = TRUE;
  $line_manager_email_cid = 0;
  $approver_notice_show = TRUE;
  $approver_notice_cid = 0;
  $approver_name_show = TRUE;
  $approver_name_cid = 0;
  $approver_email_show = TRUE;
  $approver_email_cid = 0;
  $approver_file_show = TRUE;
  $approver_file_cid = 0;
  
  //robert add 2012-09-21 [hidden the markup notice]
  //$for_allowances_calculation_show = TRUE;
  //$for_allowances_calculation_cid = 37;
  $notice_for_allowances_calculation_show = FALSE;
  $notice_for_allowances_calculation_cid = 38;
  //$is_salary_change_show = FALSE;
  //$is_salary_change_cid = 23;
  $is_salary_change_description_show = FALSE;
  $is_salary_change_description_cid = 64;
  //end robert add 2012-09-21
  
  // phase 2: change for Germany by tanky
  // Sending Work Location/Site : - Display if "Relocation Type" <> 'New Hire'
  // Sending Location/City :Display if "Relocation Type" = 'New Hire'
  // Sending Please specify : Display if "Sending Location/City" = 'Other'
  // Receiving Please specify : Display if "Receiving Location/City" = 'Other'
  $sending_work_site_show = TRUE;
  $sending_work_site_cid = 0;
  $sending_work_city_show = TRUE;
  $sending_work_city_cid = 0;
  $sending_work_city_specify_show = FALSE;
  $sending_work_city_specify_cid = 0;
  $receiving_work_city_specify_show = FALSE;
  $receiving_work_city_specify_cid = 0;
  
  // SAP ID/Personnel Number : Non-mandatory if "Relocation Type" = 'New Hire'
  $global_sap_id_mandatory = TRUE;
  $global_sap_id_cid = 0;
  // P&G Email Address : Non-mandatory if "Relocation Type" = 'New Hire'
  $email_address_mandatory = TRUE;
  $email_address_cid = 0;
  // Email Address 2: Display if "Relocation Type" = 'New Hire'
  $email_address_2_show = FALSE;
  $email_address_2_cid = 0;
  //end phase 2: change for Germany by tanky
    //phase 4 Is the Spouse/Partner a P&G Employee lower: 3 question:
  $spouse_full_name_show = FALSE;
  $spouse_full_name_cid= 0 ;
  $spouse_being_transfer_show = FALSE;
  $spouse_being_transfer_cid= 0 ;
  $spouse_id_show = FALSE;
  $spouse_id_cid= 0 ;
  foreach ($components as $cid=>$value) {
	if ($value['form_key']=='relocation_type') {//cid:24
            if ($submission->data[$value['cid']]['value'][0] == 'new_hire') {
//                $sending_work_site_show = FALSE;
//                $sending_work_city_show = TRUE;
                $email_address_2_show = TRUE;
                
                $global_sap_id_mandatory = FALSE;
                $email_address_mandatory = FALSE;
            }
            else {
                // <> 'New Hire'
//                $sending_work_site_show = TRUE;
//                $sending_work_city_show = FALSE;
            }
            //$split_family_show = FALSE;
	}
        if ($value['form_key'] == 'sending_work_location_site') {//cid:25
            $sending_work_site_cid = $value['cid'];
        }
        if ($value['form_key'] == 'sending_work_city') {//cid:57
            $sending_work_city_cid = $value['cid'];
            if ($submission->data[$value['cid']]['value'][0] == LOCATION_CITY_OTHERS) {
                $sending_work_city_specify_show = TRUE;
            }
         }
        if ($value['form_key'] == 'please_specify_sending') {//cid:65
            $sending_work_city_specify_cid = $value['cid'];
        }
        if ($value['form_key'] == 'receiving_work_city') {//cid:61
            if ($submission->data[$value['cid']]['value'][0] == LOCATION_CITY_OTHERS) {
                $receiving_work_city_specify_show = TRUE;
            }
        }
        if ($value['form_key'] == 'please_specify_receiving') {//cid:66
            $receiving_work_city_specify_cid = $value['cid'];
        }
        if ($value['form_key'] == 'receiving_company_legal_entity2') {
            $receiving_company_legal_entity2_cid = $value['cid'];
          }
          if ($value['form_key'] == 'company_code') {
            $field_company_code_cid = $value['cid'];
          }
          if ($value['form_key'] == 'company_name') {
            $field_company_name_cid = $value['cid'];
          }
        if ($value['form_key'] == 'global_sap_id') {//cid:63
            $global_sap_id_cid = $value['cid'];
        }
        if ($value['form_key'] == 'email_address') {//cid:33
            $email_address_cid = $value['cid'];
        }
        if ($value['form_key'] == 'email_address_2') {//cid:67
            $email_address_2_cid = $value['cid'];
        }
	if ($value['form_key']=='split_family') {//cid:52
	  //$split_family_cid = $value['cid'];
	}
	if($value['form_key']=='is_salary_change' && $submission->data[$value['cid']]['value'][0]!='Yes') {//cid:23
	  $salary_change_date_show = FALSE;
	}
	if ($value['form_key']=='salary_change_date') {//cid:27
	  $salary_change_date_cid = $value['cid'];
	}
	if ($value['form_key']=='relocation_initiator_role') {//cid:22
	  if ($submission->data[$value['cid']]['value'][0]!='RLM') {	
	    $rlm_confirm_info_show = FALSE;
	  }
	  else {
	    $line_manager_name_show = FALSE;
            $line_manager_email_show = FALSE;	  
		  
	    $not_rlm_confirm_info_show = FALSE;
	  }
	}
	if ($value['form_key']=='rlm_confirm_info') {//cid:53
	  $rlm_confirm_info_cid = $value['cid'];
	}
	if ($value['form_key']=='not_rlm_confirm_info') {//cid:56
	  $not_rlm_confirm_info_cid = $value['cid'];
	}
	if ($value['form_key']=='name_of_receiving_line_manager') {//cid:11
	  $line_manager_name_cid = $value['cid'];
	}
	if ($value['form_key']=='receiving_line_manager_email') {//cid:41
	  $line_manager_email_cid = $value['cid'];
	}
	if ($value['form_key']=='is_relocation_initiator_acting_as_approver' && $submission->data[$value['cid']]['value'][0]==1) {//cid:40
	  $approver_notice_show = FALSE;
  	  $approver_name_show = FALSE;
          $approver_email_show = FALSE;
          $approver_file_show = FALSE;
	}
	if ($value['form_key']=='notice_display_approver') {//cid:46
	  $approver_notice_cid = $value['cid'];
	}
	if ($value['form_key']=='name_of_approver') {//cid:18
	  $approver_name_cid = $value['cid'];
	}
	if ($value['form_key']=='approver_email') {//cid:42
	  $approver_email_cid = $value['cid'];
	}
	if ($value['form_key']=='please_attach_approval_notification') {//cid:43
	  $approver_file_cid = $value['cid'];
	}
        if ($value['form_key']=='is_the_spouse_partner_a_pg_employee' && $submission->data[$value['cid']]['value'][0]==1) {//cid:43
            $spouse_full_name_show = TRUE;
            $spouse_being_transfer_show = TRUE;
            $spouse_id_show = TRUE;
        }
        if ($value['form_key']=='if_yes_please_provide_spouse_partners_full_name') {//cid:43
          $spouse_full_name_cid = $value['cid'];
        }
        if ($value['form_key']=='is_spouse_partner_also_being_transferred') {//cid:43
          $spouse_being_transfer_cid = $value['cid'];
        }
        if ($value['form_key']=='spouse_partners_sap_id_personnel_number') {//cid:43
          $spouse_id_cid = $value['cid'];
        }
  }//endforeach
  
  //if (!$split_family_show && isset($components[$split_family_cid])) {
    //unset($components[$split_family_cid]);
  //}
  if (!$salary_change_date_show && isset($components[$salary_change_date_cid])) {
    unset($components[$salary_change_date_cid]);
  }
  if (!$rlm_confirm_info_show && isset($components[$rlm_confirm_info_cid])) {
    unset($components[$rlm_confirm_info_cid]);
  }
  if (!$not_rlm_confirm_info_show && isset($components[$not_rlm_confirm_info_cid])) {
    unset($components[$not_rlm_confirm_info_cid]);
  }
  if (!$line_manager_name_show && isset($components[$line_manager_name_cid])) {
    unset($components[$line_manager_name_cid]);
  }
  if (!$line_manager_email_show && isset($components[$line_manager_email_cid])) {
    unset($components[$line_manager_email_cid]);
  }
  if (!$approver_notice_show && isset($components[$approver_notice_cid])) {
    unset($components[$approver_notice_cid]);
  }
  if (!$approver_name_show && isset($components[$approver_name_cid])) {
    unset($components[$approver_name_cid]);
  }
  if (!$approver_email_show && isset($components[$approver_email_cid])) {
    unset($components[$approver_email_cid]);
  }
  if (!$approver_file_show && isset($components[$approver_file_cid])) {
    unset($components[$approver_file_cid]);
  }
  
  //robert add 2012-09-21 [hidden the markup notice]
  //if (!$for_allowances_calculation_show && isset($components[$for_allowances_calculation_cid])) {
  //unset($components[$for_allowances_calculation_cid]);
  //}
  if (!$notice_for_allowances_calculation_show && isset($components[$notice_for_allowances_calculation_cid])) {
    unset($components[$notice_for_allowances_calculation_cid]);
  }
  //if (!$is_salary_change_show && isset($components[$is_salary_change_cid])) {
  //unset($components[$is_salary_change_cid]);
  //}
  if (!$is_salary_change_description_show && isset($components[$is_salary_change_description_cid])) {
    unset($components[$is_salary_change_description_cid]);
  }
  //end robert add 2012-09-21
  
  // phase 2: change for Germany by tanky
  if (!$sending_work_site_show && isset($components[$sending_work_site_cid])) {
    unset($components[$sending_work_site_cid]);
  }
  if (!$sending_work_city_show && isset($components[$sending_work_city_cid])) {
    unset($components[$sending_work_city_cid]);
  }
  if (!$sending_work_city_specify_show && isset($components[$sending_work_city_specify_cid])) {
    unset($components[$sending_work_city_specify_cid]);
  }
  if (!$receiving_work_city_specify_show && isset($components[$receiving_work_city_specify_cid])) {
    unset($components[$receiving_work_city_specify_cid]);
  }
  if (!$global_sap_id_mandatory) {
    unset($components[$global_sap_id_cid]['mandatory']);
  }
  if (!$email_address_mandatory) {  
    unset($components[$email_address_cid]['mandatory']);
  }
  if (!$email_address_2_show && isset($components[$email_address_2_cid])) {
    unset($components[$email_address_2_cid]);
  }
  //end phase 2: change for Germany by tanky
    //phase 4 spouse employee
  if (!$spouse_full_name_show && isset($components[$spouse_full_name_cid])) {
    unset($components[$spouse_full_name_cid]);
  }
  if (!$spouse_being_transfer_show && isset($components[$spouse_being_transfer_cid])) {
    unset($components[$spouse_being_transfer_cid]);
  }
  if (!$spouse_id_show && isset($components[$spouse_id_cid])) {
    unset($components[$spouse_id_cid]);
  }
    if ($submission->data[$receiving_company_legal_entity2_cid]['value'][0] != '0000|None of above|None') {
    unset($components[$field_company_code_cid]);
    unset($components[$field_company_name_cid]);
  }
  //show the * in detail page
  foreach ($components as $cid => $value) {
    if (isset($value['mandatory']) && $value['mandatory'] == 1) {
      if ($format != "text") {
        $components[$cid]['name'] .= '<span class="form-required" title="This field is required.">*</span>';
      }
    }
  }
  //end show the * in detail page
}

function webform_submission_render_MEX($node, $submission, &$components, $format) {
  //$split_family_show = TRUE;
  //$split_family_cid  = 0;
  $salary_change_date_show = TRUE;
  $salary_change_date_cid = 0;  
  $rlm_confirm_info_show = TRUE;
  $rlm_confirm_info_cid = 0;
  $not_rlm_confirm_info_show = TRUE;
  $not_rlm_confirm_info_cid = 0;
  
  $line_manager_name_show = TRUE;
  $line_manager_name_cid = 0;
  $line_manager_email_show = TRUE;
  $line_manager_email_cid = 0;
  $approver_notice_show = TRUE;
  $approver_notice_cid = 0;
  $approver_name_show = TRUE;
  $approver_name_cid = 0;
  $approver_email_show = TRUE;
  $approver_email_cid = 0;
  $approver_file_show = TRUE;
  $approver_file_cid = 0;
  
  //robert add 2012-09-21 [hidden the markup notice]
  //$for_allowances_calculation_show = TRUE;
  //$for_allowances_calculation_cid = 37;
  $notice_for_allowances_calculation_show = FALSE;
  $notice_for_allowances_calculation_cid = 38;
  //$is_salary_change_show = FALSE;
  //$is_salary_change_cid = 23;
  $is_salary_change_description_show = FALSE;
  $is_salary_change_description_cid = 64;
  //end robert add 2012-09-21

  $new_hire_cid = 0;
  $sending_work_location_site_cid = 0;
  $sending_location_city_cid = 0;
  $receiving_location_city_cid = 0;
  $email_address_cid = 0;
  $email_address_2_cid = 0;
  $seding_city_specify_cid = 0;
  $receiving_city_sepcify_cid = 0;
  $global_sap_id_cid = 0;
  
  //For Allowances Calculation
  $spouse_partner_a_pg_employee_show = TRUE ;
  $spouse_partner_a_pg_employee_cid = 0;
  $spouse_partners_full_name_cid = 0 ;
  $partner_also_being_transferred_cid = 0 ;
  $spouse_partners_sap_id_cid = 0 ;
  //phase 4 Is the Spouse/Partner a P&G Employee lower: 3 question:
  $spouse_full_name_show = FALSE;
  $spouse_full_name_cid= 0 ;
  $spouse_being_transfer_show = FALSE;
  $spouse_being_transfer_cid= 0 ;
  $spouse_id_show = FALSE;
  $spouse_id_cid= 0 ;
  //show or hidden logic
  //find CID
  foreach ($components as $cid => $value) {
    if ($value['form_key'] == 'is_the_employee_a_new_hire') {
      $new_hire_cid = $value['cid'];
    }
    if ($value['form_key'] == 'sending_work_location_site') {
      $sending_work_location_site_cid = $value['cid'];
    }
    if ($value['form_key'] == 'sending_work_city') {
      $sending_location_city_cid = $value['cid'];
    }
    if ($value['form_key'] == 'receiving_work_city') {
      $receiving_location_city_cid = $value['cid'];
    }
    if ($value['form_key'] == 'receiving_company_legal_entity2') {
      $receiving_company_legal_entity2_cid = $value['cid'];
    }
    if ($value['form_key'] == 'company_code') {
      $field_company_code_cid = $value['cid'];
    }
    if ($value['form_key'] == 'company_name') {
      $field_company_name_cid = $value['cid'];
    }
    if ($value['form_key'] == 'global_sap_id') {
      $global_sap_id_cid = $value['cid'];
    }
    if ($value['form_key'] == 'email_address') {
      $email_address_cid = $value['cid'];
    }
    if ($value['form_key'] == 'email_address_2') {
      $email_address_2_cid = $value['cid'];
    }
    if ($value['form_key'] == 'please_specify_sending') {
      $seding_city_specify_cid = $value['cid'];
    }
    if ($value['form_key'] == 'please_specify_receiving') {
      $receiving_city_sepcify_cid = $value['cid'];
    }
  }
  if ($submission->data[$new_hire_cid]['value'][0] == '1') {
    //new hire
    unset($components[$global_sap_id_cid]['mandatory']);
    unset($components[$email_address_cid]['mandatory']);
  }
  if ($submission->data[$new_hire_cid]['value'][0] == '0') {
    unset($components[$email_address_2_cid]);
  }
  if ($submission->data[$sending_location_city_cid]['value'][0] != 'Others') {
    unset($components[$seding_city_specify_cid]);
  }
  if ($submission->data[$receiving_location_city_cid]['value'][0] != 'Others') {
    unset($components[$receiving_city_sepcify_cid]);
  }
  //show & hidden logic end

  foreach ($components as $cid => $value) {
    if (isset($value['mandatory']) && $value['mandatory'] == 1) {
      if ($format != "text") {
        $components[$cid]['name'] .= '<span class="form-required" title="This field is required.">*</span>';
      }
    }
    
    if ($value['form_key']=='split_family') {//cid:52
        //$split_family_cid = $value['cid'];
    }
    if($value['form_key']=='is_salary_change' && $submission->data[$value['cid']]['value'][0]!='Yes') {//cid:23
        $salary_change_date_show = FALSE;
    }
    if ($value['form_key']=='salary_change_date') {//cid:27
        $salary_change_date_cid = $value['cid'];
    }
    
      //For Allowances Calculation
    if($value['form_key']=='is_the_spouse_partner_a_pg_employee' && $submission->data[$value['cid']]['value'][0]!=1) {//cid:23
        $spouse_partner_a_pg_employee_show = FALSE;
    }
    if ($value['form_key']=='if_yes_please_provide_spouse_partners_full_name') {//cid:70
        $spouse_partners_full_name_cid = $value['cid'];
    }
    if ($value['form_key']=='is_spouse_partner_also_being_transferred') {//cid:71
        $partner_also_being_transferred_cid = $value['cid'];
    }
    if ($value['form_key']=='spouse_partners_sap_id_personnel_number') {//cid:72
        $spouse_partners_sap_id_cid = $value['cid'];
    }
    
    if ($value['form_key'] == 'relocation_initiator_role') {//cid:22
      if ($submission->data[$value['cid']]['value'][0] != 'RLM') {
        $rlm_confirm_info_show = FALSE;
      } else {
        $line_manager_name_show = FALSE;
        $line_manager_email_show = FALSE;

        $not_rlm_confirm_info_show = FALSE;
      }
    }
    if ($value['form_key'] == 'rlm_confirm_info') {//cid:53
      $rlm_confirm_info_cid = $value['cid'];
    }
    if ($value['form_key'] == 'not_rlm_confirm_info') {//cid:56
      $not_rlm_confirm_info_cid = $value['cid'];
    }
    if ($value['form_key'] == 'name_of_receiving_line_manager') {//cid:11
      $line_manager_name_cid = $value['cid'];
    }
    if ($value['form_key'] == 'receiving_line_manager_email') {//cid:41
      $line_manager_email_cid = $value['cid'];
    }
    if ($value['form_key'] == 'is_relocation_initiator_acting_as_approver' && $submission->data[$value['cid']]['value'][0] == 1 ) {//cid:40
      $approver_notice_show = FALSE;
      $approver_name_show = FALSE;
      $approver_email_show = FALSE;
      $approver_file_show = FALSE;
    }
    if ($value['form_key'] == 'notice_display_approver') {//cid:46
      $approver_notice_cid = $value['cid'];
    }
    if ($value['form_key'] == 'name_of_approver') {//cid:18
      $approver_name_cid = $value['cid'];
    }
    if ($value['form_key'] == 'approver_email') {//cid:42
      $approver_email_cid = $value['cid'];
    }
    if ($value['form_key'] == 'please_attach_approval_notification') {//cid:43
      $approver_file_cid = $value['cid'];
    }
    if ($value['form_key']=='is_the_spouse_partner_a_pg_employee' && $submission->data[$value['cid']]['value'][0]==1) {//cid:43
        $spouse_full_name_show = TRUE;
        $spouse_being_transfer_show = TRUE;
        $spouse_id_show = TRUE;
    }
    if ($value['form_key']=='if_yes_please_provide_spouse_partners_full_name') {//cid:43
      $spouse_full_name_cid = $value['cid'];
    }
    if ($value['form_key']=='is_spouse_partner_also_being_transferred') {//cid:43
      $spouse_being_transfer_cid = $value['cid'];
    }
    if ($value['form_key']=='spouse_partners_sap_id_personnel_number') {//cid:43
      $spouse_id_cid = $value['cid'];
    }
  }//endforeach

  //if (!$split_family_show && isset($components[$split_family_cid])) {
  //unset($components[$split_family_cid]);
  //}
  if (!$salary_change_date_show && isset($components[$salary_change_date_cid])) {
    unset($components[$salary_change_date_cid]);
  }

  if (!$spouse_partner_a_pg_employee_show && isset($components[$spouse_partners_full_name_cid])) {
    unset($components[$spouse_partners_full_name_cid]);
  }
  if (!$spouse_partner_a_pg_employee_show && isset($components[$partner_also_being_transferred_cid])) {
    unset($components[$partner_also_being_transferred_cid]);
  }
  if (!$spouse_partner_a_pg_employee_show && isset($components[$spouse_partners_sap_id_cid])) {
    unset($components[$spouse_partners_sap_id_cid]);
  }
  
  if (!$rlm_confirm_info_show && isset($components[$rlm_confirm_info_cid])) {
    unset($components[$rlm_confirm_info_cid]);
  }
  if (!$not_rlm_confirm_info_show && isset($components[$not_rlm_confirm_info_cid])) {
    unset($components[$not_rlm_confirm_info_cid]);
  }
  if (!$line_manager_name_show && isset($components[$line_manager_name_cid])) {
    unset($components[$line_manager_name_cid]);
  }
  if (!$line_manager_email_show && isset($components[$line_manager_email_cid])) {
    unset($components[$line_manager_email_cid]);
  }
  if (!$approver_notice_show && isset($components[$approver_notice_cid])) {
    unset($components[$approver_notice_cid]);
  }
  if (!$approver_name_show && isset($components[$approver_name_cid])) {
    unset($components[$approver_name_cid]);
  }
  if (!$approver_email_show && isset($components[$approver_email_cid])) {
    unset($components[$approver_email_cid]);
  }
  if (!$approver_file_show && isset($components[$approver_file_cid])) {
    unset($components[$approver_file_cid]);
  }
  
  //robert add 2012-09-21 [hidden the markup notice]
  //if (!$for_allowances_calculation_show && isset($components[$for_allowances_calculation_cid])) {
  //unset($components[$for_allowances_calculation_cid]);
  //}
  if (!$notice_for_allowances_calculation_show && isset($components[$notice_for_allowances_calculation_cid])) {
    unset($components[$notice_for_allowances_calculation_cid]);
  }
  //if (!$is_salary_change_show && isset($components[$is_salary_change_cid])) {
  //unset($components[$is_salary_change_cid]);
  //}
  if (!$is_salary_change_description_show && isset($components[$is_salary_change_description_cid])) {
    unset($components[$is_salary_change_description_cid]);
  }
  //end robert add 2012-09-21
    //phase 4 spouse employee
  if (!$spouse_full_name_show && isset($components[$spouse_full_name_cid])) {
    unset($components[$spouse_full_name_cid]);
  }
  if (!$spouse_being_transfer_show && isset($components[$spouse_being_transfer_cid])) {
    unset($components[$spouse_being_transfer_cid]);
  }
  if (!$spouse_id_show && isset($components[$spouse_id_cid])) {
    unset($components[$spouse_id_cid]);
  }
    if ($submission->data[$receiving_company_legal_entity2_cid]['value'][0] != '0000|None of above|None') {
    unset($components[$field_company_code_cid]);
    unset($components[$field_company_name_cid]);
  }
}






function webform_submission_render_AU($node, $submission, &$components, $format) {
  //$split_family_show = TRUE;
  //$split_family_cid  = 0;
  $salary_change_date_show = TRUE;
  $salary_change_date_cid = 0;  
  $rlm_confirm_info_show = TRUE;
  $rlm_confirm_info_cid = 0;
  $not_rlm_confirm_info_show = TRUE;
  $not_rlm_confirm_info_cid = 0;
  
  $line_manager_name_show = TRUE;
  $line_manager_name_cid = 0;
  $line_manager_email_show = TRUE;
  $line_manager_email_cid = 0;
  $approver_notice_show = TRUE;
  $approver_notice_cid = 0;
  $approver_name_show = TRUE;
  $approver_name_cid = 0;
  $approver_email_show = TRUE;
  $approver_email_cid = 0;
  $approver_file_show = TRUE;
  $approver_file_cid = 0;
  
  //robert add 2012-09-21 [hidden the markup notice]
  //$for_allowances_calculation_show = TRUE;
  //$for_allowances_calculation_cid = 37;
  $notice_for_allowances_calculation_show = FALSE;
  $notice_for_allowances_calculation_cid = 38;
  //$is_salary_change_show = FALSE;
  //$is_salary_change_cid = 23;
  $is_salary_change_description_show = FALSE;
  $is_salary_change_description_cid = 64;
  //end robert add 2012-09-21

  $new_hire_cid = 0;
  $sending_work_location_site_cid = 0;
  $sending_location_city_cid = 0;
  $receiving_location_city_cid = 0;
  $email_address_cid = 0;
  $email_address_2_cid = 0;
  $seding_city_specify_cid = 0;
  $receiving_city_sepcify_cid = 0;
  $global_sap_id_cid = 0;
  
  //For Allowances Calculation
  $spouse_partner_a_pg_employee_show = TRUE ;
  $spouse_partner_a_pg_employee_cid = 0;
  $spouse_partners_full_name_cid = 0 ;
  $partner_also_being_transferred_cid = 0 ;
  $spouse_partners_sap_id_cid = 0 ;
  //phase 4 Is the Spouse/Partner a P&G Employee lower: 3 question:
  $spouse_full_name_show = FALSE;
  $spouse_full_name_cid= 0 ;
  $spouse_being_transfer_show = FALSE;
  $spouse_being_transfer_cid= 0 ;
  $spouse_id_show = FALSE;
  $spouse_id_cid= 0 ;
  //show or hidden logic
  //find CID
  foreach ($components as $cid => $value) {
    if ($value['form_key'] == 'country_of_domestic_transfer') {
      $country_cid = $value['cid'];
    }
    if ($value['form_key'] == 'is_the_employee_a_new_hire') {
      $new_hire_cid = $value['cid'];
    }
    if ($value['form_key'] == 'sending_work_location_site') {
      $sending_work_location_site_cid = $value['cid'];
    }
    if ($value['form_key'] == 'sending_work_city') {
      $sending_location_city_cid = $value['cid'];
    }
    if ($value['form_key'] == 'receiving_work_city') {
      $receiving_location_city_cid = $value['cid'];
    }
    if ($value['form_key'] == 'global_sap_id') {
      $global_sap_id_cid = $value['cid'];
    }
    if ($value['form_key'] == 'email_address') {
      $email_address_cid = $value['cid'];
    }
    if ($value['form_key'] == 'email_address_2') {
      $email_address_2_cid = $value['cid'];
    }
    if ($value['form_key'] == 'please_specify_sending') {
      $seding_city_specify_cid = $value['cid'];
    }
    if ($value['form_key'] == 'please_specify_receiving') {
      $receiving_city_sepcify_cid = $value['cid'];
    }
    if ($value['form_key'] == 'receiving_company_legal_entity2') {
      $receiving_company_legal_entity2_cid = $value['cid'];
    }
    if ($value['form_key'] == 'company_code') {
      $field_company_code_cid = $value['cid'];
    }
    if ($value['form_key'] == 'company_name') {
      $field_company_name_cid = $value['cid'];
    }
    if ($value['form_key'] == 'function') {
      $field_function_cid = $value['cid'];
    }
    if ($value['form_key'] == 'if_cbd_please_provide_long_term_career_base') {
      $field_cbd_cid = $value['cid'];
    }
    if ($value['form_key'] == 'legal_entity_which_employee_signed_their_contract_for') {
      $field_legal_entity_contract_cid = $value['cid'];
    }
    if ($value['form_key'] == 'is_relocation_initiator_acting_as_approver') {
      $is_relocation_initiator_acting_as_approver = $value['cid'];
    }
    if ($value['form_key'] == 'name_of_approver') {
      $name_of_approver = $value['cid'];
    }
    if ($value['form_key'] == 'approver_email') {
      $approver_email = $value['cid'];
    }
    if ($value['form_key'] == 'please_attach_approval_notification') {
      $please_attach_approval_notification = $value['cid'];
    }
  }
    if ($submission->data[$new_hire_cid]['value'][0] == '1') {
        //new hire
        unset($components[$global_sap_id_cid]['mandatory']);
        unset($components[$email_address_cid]['mandatory']);
        if ($submission->data[$country_cid]['value'][0] == 'CN') {
            unset($components[$sending_work_location_site_cid]);
        }
    }
    if ($submission->data[$new_hire_cid]['value'][0] == '0') {
        unset($components[$email_address_2_cid]);
    }
  if ($submission->data[$sending_location_city_cid]['value'][0] != 'Others') {
    unset($components[$seding_city_specify_cid]);
  }
  if ($submission->data[$receiving_location_city_cid]['value'][0] != 'Others') {
    unset($components[$receiving_city_sepcify_cid]);
  }
  if ($submission->data[$receiving_company_legal_entity2_cid]['value'][0] != '0000|None of above|None') {
    unset($components[$field_company_code_cid]);
    unset($components[$field_company_name_cid]);
  }
  
  if ($submission->data[$country_cid]['value'][0] != 'CN') {
    unset($components[$field_function_cid]);
    unset($components[$field_cbd_cid]);
  }else{
      unset($components[$is_relocation_initiator_acting_as_approver]);
      unset($components[$name_of_approver]);
      unset($components[$approver_email]);
      unset($components[$please_attach_approval_notification]);
  }
  if ($submission->data[$country_cid]['value'][0] != 'CN'||$submission->data[$field_function_cid]['value'][0]=='cn_CUSTOMER_BUSINESS_DEVELOPMENT_SALES') {
    unset($components[$field_legal_entity_contract_cid]);
  }
  //show & hidden logic end

  foreach ($components as $cid => $value) {
    if (isset($value['mandatory']) && $value['mandatory'] == 1) {
      if ($format != "text") {
        $components[$cid]['name'] .= '<span class="form-required" title="This field is required.">*</span>';
      }
    }
    
    if ($value['form_key']=='split_family') {//cid:52
        //$split_family_cid = $value['cid'];
    }
    if($value['form_key']=='is_salary_change' && $submission->data[$value['cid']]['value'][0]!='Yes') {//cid:23
        $salary_change_date_show = FALSE;
    }
    if ($value['form_key']=='salary_change_date') {//cid:27
        $salary_change_date_cid = $value['cid'];
    }
    
      //For Allowances Calculation
    if($value['form_key']=='is_the_spouse_partner_a_pg_employee' && $submission->data[$value['cid']]['value'][0]!=1) {//cid:23
        $spouse_partner_a_pg_employee_show = FALSE;
    }
    if ($value['form_key']=='if_yes_please_provide_spouse_partners_full_name') {//cid:70
        $spouse_partners_full_name_cid = $value['cid'];
    }
    if ($value['form_key']=='is_spouse_partner_also_being_transferred') {//cid:71
        $partner_also_being_transferred_cid = $value['cid'];
    }
    if ($value['form_key']=='spouse_partners_sap_id_personnel_number') {//cid:72
        $spouse_partners_sap_id_cid = $value['cid'];
    }
    
    if ($value['form_key'] == 'relocation_initiator_role') {//cid:22
      if ($submission->data[$value['cid']]['value'][0] != 'RLM') {
        $rlm_confirm_info_show = FALSE;
      } else {
        $line_manager_name_show = FALSE;
        $line_manager_email_show = FALSE;
        $not_rlm_confirm_info_show = FALSE;
      }
        if ($submission->data[$country_cid]['value'][0] != 'CN') {
            $line_manager_name_show = TRUE;
            $line_manager_email_show = TRUE;
        }
    }
    if ($value['form_key'] == 'rlm_confirm_info') {//cid:53
      $rlm_confirm_info_cid = $value['cid'];
    }
    if ($value['form_key'] == 'not_rlm_confirm_info') {//cid:56
      $not_rlm_confirm_info_cid = $value['cid'];
    }
    if ($value['form_key'] == 'name_of_receiving_line_manager') {//cid:11
      $line_manager_name_cid = $value['cid'];
    }
    if ($value['form_key'] == 'receiving_line_manager_email') {//cid:41
      $line_manager_email_cid = $value['cid'];
    }
    if ($value['form_key'] == 'is_relocation_initiator_acting_as_approver' && $submission->data[$value['cid']]['value'][0] == 1 ) {//cid:40
      $approver_notice_show = FALSE;
      $approver_name_show = FALSE;
      $approver_email_show = FALSE;
      $approver_file_show = FALSE;
    }
    if ($value['form_key'] == 'notice_display_approver') {//cid:46
      $approver_notice_cid = $value['cid'];
    }
    if ($value['form_key'] == 'name_of_approver') {//cid:18
      $approver_name_cid = $value['cid'];
    }
    if ($value['form_key'] == 'approver_email') {//cid:42
      $approver_email_cid = $value['cid'];
    }
    if ($value['form_key'] == 'please_attach_approval_notification') {//cid:43
      $approver_file_cid = $value['cid'];
    }
    if ($value['form_key']=='is_the_spouse_partner_a_pg_employee' && $submission->data[$value['cid']]['value'][0]==1) {//cid:43
        $spouse_full_name_show = TRUE;
        $spouse_being_transfer_show = TRUE;
        $spouse_id_show = TRUE;
    }
    if ($value['form_key']=='if_yes_please_provide_spouse_partners_full_name') {//cid:43
      $spouse_full_name_cid = $value['cid'];
    }
    if ($value['form_key']=='is_spouse_partner_also_being_transferred') {//cid:43
      $spouse_being_transfer_cid = $value['cid'];
    }
    if ($value['form_key']=='spouse_partners_sap_id_personnel_number') {//cid:43
      $spouse_id_cid = $value['cid'];
    }
  }//endforeach

  //if (!$split_family_show && isset($components[$split_family_cid])) {
  //unset($components[$split_family_cid]);
  //}
  if (!$salary_change_date_show && isset($components[$salary_change_date_cid])) {
    unset($components[$salary_change_date_cid]);
  }

  if (!$spouse_partner_a_pg_employee_show && isset($components[$spouse_partners_full_name_cid])) {
    unset($components[$spouse_partners_full_name_cid]);
  }
  if (!$spouse_partner_a_pg_employee_show && isset($components[$partner_also_being_transferred_cid])) {
    unset($components[$partner_also_being_transferred_cid]);
  }
  if (!$spouse_partner_a_pg_employee_show && isset($components[$spouse_partners_sap_id_cid])) {
    unset($components[$spouse_partners_sap_id_cid]);
  }
  
  if (!$rlm_confirm_info_show && isset($components[$rlm_confirm_info_cid])) {
    unset($components[$rlm_confirm_info_cid]);
  }
  if (!$not_rlm_confirm_info_show && isset($components[$not_rlm_confirm_info_cid])) {
    unset($components[$not_rlm_confirm_info_cid]);
  }
  if (!$line_manager_name_show && isset($components[$line_manager_name_cid])) {
    unset($components[$line_manager_name_cid]);
  }
  if (!$line_manager_email_show && isset($components[$line_manager_email_cid])) {
    unset($components[$line_manager_email_cid]);
  }
  if (!$approver_notice_show && isset($components[$approver_notice_cid])) {
    unset($components[$approver_notice_cid]);
  }
  if (!$approver_name_show && isset($components[$approver_name_cid])) {
    unset($components[$approver_name_cid]);
  }
  if (!$approver_email_show && isset($components[$approver_email_cid])) {
    unset($components[$approver_email_cid]);
  }
  if (!$approver_file_show && isset($components[$approver_file_cid])) {
    unset($components[$approver_file_cid]);
  }
  
  //robert add 2012-09-21 [hidden the markup notice]
  //if (!$for_allowances_calculation_show && isset($components[$for_allowances_calculation_cid])) {
  //unset($components[$for_allowances_calculation_cid]);
  //}
  if (!$notice_for_allowances_calculation_show && isset($components[$notice_for_allowances_calculation_cid])) {
    unset($components[$notice_for_allowances_calculation_cid]);
  }
  //if (!$is_salary_change_show && isset($components[$is_salary_change_cid])) {
  //unset($components[$is_salary_change_cid]);
  //}
  if (!$is_salary_change_description_show && isset($components[$is_salary_change_description_cid])) {
    unset($components[$is_salary_change_description_cid]);
  }
  //end robert add 2012-09-21
    //phase 4 spouse employee
  if (!$spouse_full_name_show && isset($components[$spouse_full_name_cid])) {
    unset($components[$spouse_full_name_cid]);
  }
  if (!$spouse_being_transfer_show && isset($components[$spouse_being_transfer_cid])) {
    unset($components[$spouse_being_transfer_cid]);
  }
  if (!$spouse_id_show && isset($components[$spouse_id_cid])) {
    unset($components[$spouse_id_cid]);
  }
}
